/*
 * uart.h
 *
 * Created: 2012-11-28 20:58:58
 *  Author: ant
 */ 

/*
	Tested on 
	"13MIPEX-2.24.2"
*/

#ifndef UART_H_
#define UART_H_


#define SOFTUBR ((F_OSC/16/BAUD-1)/2)

#define MYUBRR (F_OSC/16/9600-1)

#define P_VER	0x0004

#include "../sc-p/sc-p.h"
#include "../sc-p/main.h"
#include "../sc-p/utils.h"
#include "../sc-p/trans-p.h"
#include "../sc-p/measure.h"
#include "../sc-k/SWLcd.h"

extern u8 r_buff[32];
extern u8 t_buff[32];
extern u8 rx_len;
extern u8 tx_len;
extern u8 cur_tx;
extern u8 uart_err_cnt;


void recv_data();

void recv_spec();

u8 recv_bytes();
void prep_recv();

void send_command();

void send(char* data, u8 len);


extern u16 eep_cnt;

extern u8 save_next;
void search_eep();

#ifdef MEDIA_CH4IR
//#define T2_START	TCCR2B = 2
//#define T2_START_SLOW	TCCR2B = 6
//#define T2_STOP		TCCR2B = 0
//#define T2			TCNT2

#define T2_RUN	TCCR2B = 0x07;
#define T2_HALT	TCCR2B = 0;


extern u16 xxxrom;

extern u8 ibit;

extern u8 err;

extern u16 sens_value;		// value set by order from pS, CALB xxxx
//
#define TIMEOUT	(TIFR2 & (1 << OCF2A))


#define T2CLEAR { TIFR2 |= (1 << OCF2A); TCNT2 = 0; }

#define TX_H	PORTB |= (1 << 7);
#define TX_L	PORTB &=~(1 << 7);


void set_clock_high();
void set_clock_low();


#define CODE_INIT	0xFFF2
#define CODE_FACT	0xFFF4
#define CODE_ZERO	0xFFF6		// accepted
#define CODE_SENS	0xFFF8		// accepted
#define CODE_ERR	0xFFF0
#define CODE_SERVC	0xFFFA		// refused to calib s
#define CODE_SERVZ	0xFFFB		// refused to calib z


#define MAX_EEPROM	1000		// 1024 bytes max

#endif	// MEDIA_CH4IR




#endif /* UART_H_ */